import https from '@/utils/https'
import { praseStrEmpty } from "@/utils/ruoyi";

// 查询用户列表
export const listUser = (query) => {
  return https({
    url: '/system/user/list',
    method: 'get',
    params: query
  })
}

// 查询用户详细
export const getUser = (userId) => {
  return https({
    url: '/system/user/' + praseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export const addUser = (data) => {
  return https({
    url: '/system/user',
    method: 'post',
    data: data
  })
}

// 修改用户
export const updateUser = (data) => {
  return https({
    url: '/system/user',
    method: 'put',
    data: data
  })
}

// 删除用户
export const delUser = (userId) => {
  return https({
    url: '/system/user/' + userId,
    method: 'delete'
  })
}

// 用户密码重置
export const resetUserPwd = (userId, password) => {
  const data = {
    userId,
    password
  }
  return https({
    url: '/system/user/resetPwd',
    method: 'put',
    data: data
  })
}

// 用户状态修改
export const changeUserStatus = (userId, status) => {
  const data = {
    userId,
    status
  }
  return https({
    url: '/system/user/changeStatus',
    method: 'put',
    data: data
  })
}

// 查询用户个人信息
export const getUserProfile = () => {
  return https({
    url: '/system/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export const updateUserProfile = (data) => {
  return https({
    url: '/system/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export const updateUserPwd = (oldPassword, newPassword) => {
  const data = {
    oldPassword,
    newPassword
  }
  return https({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 用户头像上传
export const uploadAvatar = (data) => {
  return https({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: data
  })
}

// 查询授权角色
export const getAuthRole = (userId) => {
  return https({
    url: '/system/user/authRole/' + userId,
    method: 'get'
  })
}

// 保存授权角色
export const updateAuthRole = (data) => {
  return https({
    url: '/system/user/authRole',
    method: 'put',
    params: data
  })
}
